package router

import (
	"awesomeProject/src/main/db"
	"awesomeProject/src/main/handler/order"
	"awesomeProject/src/main/service/orderServiceImpl"
	"github.com/gin-gonic/gin"
	"net/http"
)

func InitRouters() *gin.Engine{
	Router := gin.Default()
	// 路由分组
	ApiGroup := Router.Group("/v1/")
	OrdersRouter(ApiGroup)
	//启动HTTP服务，默认在8080启动，也可以自己配置端口号

	//GET请求方式 /hello请求路径
	Router.GET("/hello", func(c *gin.Context) {
		//c.JSON(200,gin.H{

		c.String(http.StatusOK,"hello world!")
		//})
	})
	Router.Run(":8081")



	return Router
}
// Orders 模块
func OrdersRouter(Router *gin.RouterGroup) {
	//orderServiceImpl.NewOrderServiceImpl(db.NewOrderDao(db.Db)))
	//todo 没看懂语法
	orderHandler := order.NewOrderHandler(orderServiceImpl.NewOrderServiceImpl(db.NewOrderDao(db.NewDB())))
	v1 := Router.Group("/")
	{
		v1.GET("orders", orderHandler.GetAllOrder)
		v1.POST("orders", orderHandler.AddNewOrder)
		v1.GET("orders/:id", orderHandler.GetOneOrder)//根据ID查询
		v1.PUT("orders/", orderHandler.UpdateOrder)
		v1.DELETE("orders/:id", orderHandler.DeleteOrder)
	}
}
